package gu.simplemq.stomp;

import java.util.Properties;

import org.projectodd.stilts.stomp.client.StompClient;

import gu.simplemq.MQConstProvider;
import gu.simplemq.MQProperties;
import gu.simplemq.MQPropertiesHelper;
import gu.simplemq.pool.BaseMQPool.MQPoolException;


public class PropertiesHelper extends MQPropertiesHelper {
	public static final PropertiesHelper SHELPER = new PropertiesHelper();

	PropertiesHelper() {
	}

	@Override
	public MQConstProvider getConstProvider() {
		return StompConstProvider.SPROVIDER;
	}

	@Override
	public void checkConnect(Properties input, Integer timeoutMills) {
		MQProperties props = initParameters(input);
	    try (StompPoolLazy pool = StompPoolLazys.getInstance(props)){
	    	StompClient stompClient = pool.borrow();
	    	pool.release(stompClient);
		} 
	}

	@Override
	public boolean testConnect(Properties props,Integer timeoutMills) {
		try {
			checkConnect(props, timeoutMills);
			return true;
		} catch (MQPoolException e) {
		      return false;
		}
	}
}
